<template>
  <div class="wrapper">
    <swiper :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for="item of banners" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  data () {
    return {
      banners: [
        {
          id: 0,
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1805/e5/59fad13a64807d02.jpg_750x200_713ae984.jpg'
        },
        {
          id: 1,
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1806/3c/c72a1ccd4d7b2202.jpg_750x200_b88bbab4.jpg'
        }
      ],
      swiperOption: {
        autoplay: 5000,
        initialSlide: 0,
        loop: true, // 支持轮播
        pagination: '.swiper-pagination',
        onSlideChangeEnd: swiper => {
          console.log('onSlideChangeEnd', swiper.realIndex)
        }
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  /* >>>做事件穿透，意思是只要在wrapper下面的swiper-pagination-bullet-active都要强制执行 */
  .wrapper >>> .swiper-pagination-bullet-active
    background-color #fff!important
  .wrapper
    width 100%
    height 0
    overflow hidden
    padding-bottom 27%
    background-color #eee
    /* 或者是  width 100%   height 27vm  但是兼容性不高*/
    .swiper-img
      width 100%
</style>
